#include <Fw/Sm/SmSignalBuffer.hpp>
#include <Fw/Types/Assert.hpp>

namespace Fw {

SmSignalBuffer::SmSignalBuffer(const U8* args, Serializable::SizeType size) : m_bufferData{} {
    FW_ASSERT(args != nullptr);
    FW_ASSERT(size <= sizeof(this->m_bufferData));
    SerializeStatus stat = SerializeBufferBase::setBuff(args, size);
    FW_ASSERT(FW_SERIALIZE_OK == stat, static_cast<FwAssertArgType>(stat));
}

SmSignalBuffer::SmSignalBuffer() : m_bufferData{} {}

SmSignalBuffer::~SmSignalBuffer() {}

SmSignalBuffer::SmSignalBuffer(const SmSignalBuffer& other) : Fw::SerializeBufferBase(), m_bufferData{} {
    FW_ASSERT(other.getBuffAddr() != nullptr);
    FW_ASSERT(other.getSize() <= sizeof(this->m_bufferData));

    SerializeStatus stat = SerializeBufferBase::setBuff(other.m_bufferData, other.getSize());
    FW_ASSERT(FW_SERIALIZE_OK == stat, static_cast<FwAssertArgType>(stat));
}

SmSignalBuffer& SmSignalBuffer::operator=(const SmSignalBuffer& other) {
    if (this == &other) {
        return *this;
    }

    FW_ASSERT(other.getBuffAddr() != nullptr);
    FW_ASSERT(other.getSize() <= sizeof(this->m_bufferData));

    SerializeStatus stat = SerializeBufferBase::setBuff(other.m_bufferData, other.getSize());
    FW_ASSERT(FW_SERIALIZE_OK == stat, static_cast<FwAssertArgType>(stat));
    return *this;
}

Serializable::SizeType SmSignalBuffer::getCapacity() const {
    return sizeof(this->m_bufferData);
}

Serializable::SizeType SmSignalBuffer::getBuffCapacity() const {
    return this->getCapacity();
}

const U8* SmSignalBuffer::getBuffAddr() const {
    return this->m_bufferData;
}

U8* SmSignalBuffer::getBuffAddr() {
    return this->m_bufferData;
}

}  // namespace Fw
